package cn.ivicar.cloud.gps;

public class GISUtil3 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        GISUtil3 gis = new GISUtil3();
        MessageBean params = new MessageBean();
        params.setLatitude(39.900276d);
        params.setLongitude(116.393246d);
        gis.getDeflexedCoordinate(params);
        System.out.println(params.getAmapLng() + "," + params.getAmapLat());
        System.out.println("耗时:" + (System.currentTimeMillis() - start) + "ms");
    }

    public void getDeflexedCoordinate(MessageBean params) {
        double[] geoPoint = fromGpsToAMap(params.getLatitude(), params.getLongitude());
        if (null != geoPoint) {
            params.setAmapLat(geoPoint[0]);
            params.setAmapLng(geoPoint[1]);
        }
    }

    public static double[] fromGpsToAMap(double lng, double lat) {
        try {
            double[] latLng = ConverterUtils.gpsToAMapPoint(lat, lng);
            return new double[] { latLng[1], latLng[0] };
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return null;
    }

    public static double[] fromSeveralGpsToAMap(String latLngs) {
        try {
            String[] latLngArr = latLngs.split(",");
            int i = latLngArr.length;
            double[] aMapPoints = new double[i];
            for (int j = 0; j < i / 2; j++) {
                double[] arrayOfDouble2 = ConverterUtils.gpsToAMapPoint(Double.parseDouble(latLngArr[(j * 2)]),
                        Double.parseDouble(latLngArr[(j * 2 + 1)]));

                aMapPoints[(j * 2)] = arrayOfDouble2[0];
                aMapPoints[(j * 2 + 1)] = arrayOfDouble2[1];
            }

            return aMapPoints;
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return null;
    }

    public static double[] fromSeveralGpsToAMap(double[] gpsLatLngs) {
        try {
            int i = gpsLatLngs.length;
            double[] aMapLatLngs = new double[i];
            for (int j = 0; j < i / 2; j++) {
                double[] aMapLatLng = ConverterUtils.gpsToAMapPoint(gpsLatLngs[(j * 2)], gpsLatLngs[(j * 2 + 1)]);
                aMapLatLngs[(j * 2)] = aMapLatLng[0];
                aMapLatLngs[(j * 2 + 1)] = aMapLatLng[1];
            }

            return aMapLatLngs;
        } catch (Throwable e) {
            e.printStackTrace();
        }

        return null;
    }
}
